<%--
  Created by IntelliJ IDEA.
  User: sy189
  Date: 2022/6/1
  Time: 15:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!-- Modal -->
<div class="modal fade" id="admin_edit_user_model" tabindex="-1" role="dialog"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title text-info">用户注册</h5>
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form method="post" action="<%=request.getContextPath() %>/admin_update_user_info.action">
                <div class="modal-body">
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">用户名</label>
                        <input type="hidden" name="id" id="hidden_id" value="">
                        <div class="col-sm-10">
                            <input class="form-control" id="username_up" name="un" type="text"
                                   required/> <span class="text-danger" id="checkInfo"></span>
                        </div>

                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">密码</label>
                        <div class="col-sm-10">
                            <input class="form-control" id="password_up" name="pw" type="password" required/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">电话</label>
                        <div class="col-sm-10">
                            <input class="form-control" name="tel" id="telephone_up" type="number" required/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">地址</label>
                        <div class="col-sm-10">
                            <input class="form-control" id="address_up" name="addr" type="text" required/>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary"
                            data-dismiss="modal">关闭
                    </button>
                    <button type="submit" class="btn btn-primary">确定</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    //获取tbody下的所有tr
    var trs = document.querySelectorAll("tbody tr");
    //获取模态框的五个input

    var hidden_id = document.getElementById("hidden_id");
    var username = document.querySelector("#username_up");
    var password = document.querySelector("#password_up");
    var telephone = document.querySelector("#telephone_up");
    var address = document.querySelector("#address_up");
    console.log(trs);
    console.log(trs[1].children[0].innerHTML);
    console.log(trs[1].children[0]);
    //trs的第8个孩子点击，将trs每一个子节点的内容赋值给模态框的input
    for (let i = 0; i < trs.length; i++) {
        trs[i].children[7].children[0].onclick = function () {
            console.log(trs[i].children[0].innerHTML);
            hidden_id.value = trs[i].children[0].innerHTML;
            username.value = trs[i].children[1].innerHTML;
            password.value = trs[i].children[2].innerHTML;
            telephone.value = trs[i].children[4].innerHTML;
            address.value = trs[i].children[5].innerHTML;
        }
    }
    //获取trs 的
</script>